---
# tasks file for nginx
- name: nginx | install nginx
  apt:
    name: nginx
    state: latest
    update_cache: yes

- name: nginx | remove default site
  file:
    path: "{{ nginx_default_vhost_path }}"
    state: absent
  when: nginx_remove_default

- name: nginx | configure sites
  template:
    src: "{{ item }}"
    dest: "{{ nginx_sites_available_path }}"
    backup: "yes"
  with_fileglob:
    - "{{ nginx_template_path }}/*.conf.j2"
  notify:
    - "check nginx configuration"
    - "service nginx reload"

- name: nginx | enable new vhost in nginx
  file:
    src: "{{ nginx_sites_available_path }}/{{ item | basename }}"
    dest: "{{ nginx_sites_enabled_path }}{{ item  | basename }}"
    state: link
  with_fileglob:
    - "{{ nginx_template_path }}/*.conf.j2"